<template>
  <div id="main" />
</template>

<script>
import { getEmpType } from '@/api/graph'

export default {
  name: 'EmpTypeCount',
  data() {
    return {
      options: {
        title: {
          text: '员工类型',
          subtext: '华南',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        series: [
          {
            name: 'Access From',
            type: 'pie',
            radius: '50%',
            data: [
              {
                value: '', name: ''
              }
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }
    }
  },
  mounted() {
    this.getGraphData()
  },
  methods: {
    getGraphData() {
      const myChart = this.$echarts.init(document.getElementById('main'))
      getEmpType().then(response => {
        const datas = response.content
        const params = JSON.parse(JSON.stringify(this.options))
        const old = params.series[0].data
        // 注意： for in 是用于遍历对象属性的
        for (let j = 0; (j < datas.length); j++) {
          const item = { }
          item['value'] = datas[j]['count']
          item['name'] = datas[j]['type']
          old.push(item)
        }
        myChart.setOption(params)
      })
    }
  }
}
</script>

<style scoped>
#main {
  width: 500px;
  height: 500px;
}
</style>
